<template>
	<view>
		<uni-list>
			<uni-list-item v-for="(item,index) in data" :key="index" :title="item.c_id + item.c_name" showArrow
				clickable @tap="todetail(item)"></uni-list-item>
		</uni-list>
		
		<!-- 模板中使用 -->
		<Drag @dragClick="dragClick" creatTop="500" creatLeft="280" image="../../static/jia.png" imageWidth="70%"></Drag>
		
	</view>
	
</template>


<script>
	// 导入并注册
	import Drag from '../../components/beyondGod-drag/beyoundGod-drag.vue'
	export default {
		data() {
			return {
				data: [],
				page: 1,
				maxPage: 0,
			}
		},
		components:{
		    Drag
		},
		onLoad() {
			this.onloaddata();
		},
		onReachBottom() {
			if (this.page > this.maxPage) {
				uni.showToast({
					title: '已到达最后一页',
					icon: 'none'
				});
				return;
			}
			uni.request({
				url: this.url + 'customer/index/page_' + this.page,
				method: 'GET',
				data: {},
				success: res => {
					this.page += 1;
					this.data = this.data.concat(res.data.data[0]);
				},
			});
		},


		onPullDownRefresh() {
			this.page=1,
			this.maxPage=0,
			this.onloaddata();
		},

		methods: {
			dragClick(){
				uni.navigateTo({
					url: '/pages/customeradd/customeradd'
				});
			},
			onloaddata() {
				uni.request({
					url: this.url + 'customer/index',
					method: 'GET',
					data: {},
					success: res => {
						this.data = res.data.data[0];
						this.maxPage = res.data.data[1].maxPage;
						this.page += 1;
						uni.stopPullDownRefresh();
						
					},
				});
			},
			
			todetail(x) {
				uni.navigateTo({
					url: '/pages/customerdetail/customerdetail'
				});

				uni.$emit('sendcustomerid', {
					cid: x.c_id,
					cname: x.c_name
				})
			}
		}
	}
</script>

<style>

</style>
